*** Figures
use "experimental_data.dta", clear		

preserve
* Generate mean and median response times and SEs
gen med_response_time=.
gen med_response_time_se=.
gen cons=0

gen mean_response_time = .
gen mean_response_time_se = .

foreach i in no low high{
	foreach j in anchoring brn_abstract brn_intuitive crt wason_abstract wason_intuitive{
		
		qreg2 norm_response_time cons if condition=="`i'" & task_type=="`j'", cl(id)
		replace med_response_time=_b[_cons] if condition=="`i'" & task_type=="`j'"
		replace med_response_time_se=_se[_cons] if condition=="`i'" & task_type=="`j'"
		
		reg norm_response_time if condition == "`i'" & task_type == "`j'", cl(id)
		replace mean_response_time = _b[_cons] if condition == "`i'" & task_type == "`j'"
		replace mean_response_time_se = _se[_cons] if condition == "`i'" & task_type == "`j'"
		}
}

gen mean_performance = .
gen mean_performance_se = .


* Generate mean performance and SEs
foreach i in no low high {
	foreach j in crt brn_abstract brn_intuitive wason_abstract wason_intuitive {
		reg correct if task_type=="`j'" & condition == "`i'", cl(id)
		replace mean_performance = _b[_cons] if task_type=="`j'" & condition == "`i'"
		replace mean_performance_se = _se[_cons] if task_type=="`j'" & condition == "`i'"
	}

	gen response_temp = response if task_type == "anchoring" & condition == "`i'"
	gen anchor_temp = anchor if task_type == "anchoring" & condition == "`i'"
	egen response_std = std(response_temp)
	egen anchor_std = std(anchor_temp)

	*Obtain correlation and clustered SE for anchoring
	reg response_std anchor_std if task_type=="anchoring" & condition == "`i'", noconstant cl(id)
	replace mean_performance = 1 - _b[anchor_std] if task_type=="anchoring" & condition == "`i'"
	replace mean_performance_se = _se[anchor_std] if task_type=="anchoring" & condition == "`i'"

	drop response_temp anchor_temp response_std anchor_std
}

egen tag = tag(task_type condition_number)
keep if tag == 1
drop tag

sort task_type condition_number

keep mean_performance mean_performance_se mean_response_time mean_response_time_se med_response_time med_response_time_se ///
	 norm_expert_pred_response norm_expert_pred_se_response expert_pred_performance expert_pred_se_performance ///
	 task_type condition_number condition

	
*** Generate mean and SE for performance and response times
	
gen upper_performance=mean_performance+mean_performance_se
gen lower_performance=mean_performance-mean_performance_se

gen upper_response=mean_response_time+mean_response_time_se
gen lower_response=mean_response_time-mean_response_time_se

gen upper_response_med=med_response_time+med_response_time_se
gen lower_response_med=med_response_time-med_response_time_se


** Expert predictions

replace expert_pred_performance=mean_performance if condition=="no"
replace norm_expert_pred_response=mean_response_time if condition=="no" 


*** Figure 1 Response times

* Wason
tw 	(scatter mean_response_time condition_number if task_type=="wason_abstract", color(navy)) ///
	(rcap upper_response lower_response condition_number if task_type=="wason_abstract", lcolor(navy)) ///
	(line mean_response_time condition_number if task_type=="wason_abstract", lcolor(navy)) ///
	(scatter mean_response_time condition_number if task_type=="wason_intuitive", color(maroon) msymbol(triangle)) ///
	(rcap upper_response lower_response condition_number if task_type=="wason_intuitive", lcolor(maroon)) ///
	(line mean_response_time condition_number if task_type=="wason_intuitive", lcolor(maroon) lpattern(shortdash) ///
	graphregion(color(white)) yline(1.6,lstyle(grid)) yscale(range(0.7 1.61)) ylabel(0.8(0.2)1.6, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("Normalized response time") xtitle("") title("Contingent reasoning") ///
	legend(order(3 6) label(3 "Abstract Wason") label(6 "Intuitive Wason") r(1)))
	graph export "Figures/Wason_response.pdf", replace
	
* BRN
tw 	(scatter mean_response_time condition_number if task_type=="brn_abstract", color(navy)) ///
	(rcap upper_response lower_response condition_number if task_type=="brn_abstract", lcolor(navy)) ///
	(line mean_response_time condition_number if task_type=="brn_abstract", lcolor(navy)) ///
	(scatter mean_response_time condition_number if task_type=="brn_intuitive", color(maroon) msymbol(triangle)) ///
	(rcap upper_response lower_response condition_number if task_type=="brn_intuitive", lcolor(maroon)) ///
	(line mean_response_time condition_number if task_type=="brn_intuitive", lcolor(maroon) lpattern(shortdash) ///
	graphregion(color(white)) yline(1.6,lstyle(grid)) yscale(range(0.7 1.61)) ylabel(0.8(0.2)1.6, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("Normalized response time") xtitle("") title("Base rate neglect") ///
	legend(order(3 6) label(3 "Abstract BRN") label(6 "Intuitive BRN") r(1)))
	graph export "Figures/brn_response.pdf", replace

* CRT
tw 	(scatter mean_response_time condition_number if task_type=="crt", color(navy)) ///
	(rcap upper_response lower_response condition_number if task_type=="crt", lcolor(navy)) ///
	(line mean_response_time condition_number if task_type=="crt", lcolor(navy) ///
	graphregion(color(white)) yline(1.6,lstyle(grid)) yscale(range(0.7 1.61)) ylabel(0.8(0.2)1.6, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("Normalized response time") xtitle("") title("Cognitive Reflection Test") ///
	legend(order(3 6) label(3 "CRT") r(1)))
	graph export "Figures/crt_response.pdf", replace

* Anchoring
tw 	(scatter mean_response_time condition_number if task_type=="anchoring", color(navy)) ///
	(rcap upper_response lower_response condition_number if task_type=="anchoring", lcolor(navy)) ///
	(line mean_response_time condition_number if task_type=="anchoring", lcolor(navy) ///
	graphregion(color(white)) yline(1.6,lstyle(grid)) yscale(range(0.7 1.61)) ylabel(0.8(0.2)1.6, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("Normalized response time") xtitle("") title("Anchoring") ///
	legend(order(3 6) label(3 "Anchoring") r(1)))
	graph export "Figures/anchoring_response.pdf", replace


*** Figure 2 Performance

* Wason
tw 	(scatter mean_performance condition_number if task_type=="wason_abstract", color(navy)) ///
	(rcap upper_performance lower_performance condition_number if task_type=="wason_abstract", lcolor(navy)) ///
	(line mean_performance condition_number if task_type=="wason_abstract", lcolor(navy)) ///
	(scatter mean_performance condition_number if task_type=="wason_intuitive", color(maroon) msymbol(triangle)) ///
	(rcap upper_performance lower_performance condition_number if task_type=="wason_intuitive", lcolor(maroon)) ///
	(line mean_performance condition_number if task_type=="wason_intuitive", lcolor(maroon) lpattern(shortdash) ///
	graphregion(color(white)) yline(.8,lstyle(grid))	ylabel(0(0.2).8, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("Fraction correct") xtitle("") title("Contingent reasoning") ///
	legend(order(3 6) label(3 "Abstract Wason") label(6 "Intuitive Wason") r(1)))
	graph export "Figures/Wason.pdf", replace

* BRN
tw 	(scatter mean_performance condition_number if task_type=="brn_abstract", color(navy)) ///
	(rcap upper_performance lower_performance condition_number if task_type=="brn_abstract", lcolor(navy)) ///
	(line mean_performance condition_number if task_type=="brn_abstract", lcolor(navy)) ///
	(scatter mean_performance condition_number if task_type=="brn_intuitive", color(maroon) msymbol(triangle)) ///
	(rcap upper_performance lower_performance condition_number if task_type=="brn_intuitive", lcolor(maroon)) ///
	(line mean_performance condition_number if task_type=="brn_intuitive", lcolor(maroon) lpattern(shortdash) ///
	graphregion(color(white)) yline(.8,lstyle(grid))	ylabel(0(0.2).8, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("Fraction correct") xtitle("") title("Base rate neglect") ///
	legend(order(3 6) label(3 "Abstract BRN") label(6 "Intuitive BRN") r(1)))
	graph export "Figures/brn.pdf", replace
	
* CRT
tw 	(scatter mean_performance condition_number if task_type=="crt", color(navy)) ///
	(rcap upper_performance lower_performance condition_number if task_type=="crt", lcolor(navy)) ///
	(line mean_performance condition_number if task_type=="crt", lcolor(navy) ///
	graphregion(color(white)) yline(.8,lstyle(grid))	ylabel(0(0.2).8, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("Fraction correct") xtitle("") title("Cognitive Reflection Test") ///
	legend(order(3 6) label(3 "CRT") r(1)))
	graph export "Figures/crt.pdf", replace
	
* Anchoring
tw 	(scatter mean_performance condition_number if task_type=="anchoring", color(navy)) ///
	(rcap upper_performance lower_performance condition_number if task_type=="anchoring", lcolor(navy)) ///
	(line mean_performance condition_number if task_type=="anchoring", lcolor(navy) ///
	graphregion(color(white)) yline(.8,lstyle(grid)) yline(0,lstyle(grid))	ylabel(0(0.2).8, angle(0) glwidth(thin) glcolor(gs15)) ///
	xlabel(0.25 "No incentives" 1 "Standard incentives" 1.75 "High incentives", angle(0) glwidth(thin) glcolor(gs15)) xscale(range(0 2)) ytitle("One minus correlation b/w response and anchor") xtitle("") title("Anchoring") ///
	legend(order(3) label(3 "Anchoring") r(1)))
	graph export "Figures/anchoring.pdf", replace
restore	
